#include "StdAfx.h"
#include ".\memdc.h"

CMemDc::CMemDc(HDC hDC,const CSize& szPaint)
{
	m_hDC=hDC;
	m_NewDc=::CreateCompatibleDC (hDC);
	if (!m_NewDc)
	{
		ASSERT(FALSE);
		return;
	}
	m_MapDc=::CreateCompatibleBitmap(hDC, szPaint.cx, szPaint.cy);
	m_hOldDc = ::SelectObject (m_NewDc, (HGDIOBJ)m_MapDc);
}

CMemDc::CMemDc( HDC hDC,const CBitmap* bmMap )
{
	m_hDC=hDC;
	m_NewDc=::CreateCompatibleDC (hDC);
	if (!m_NewDc)
	{
		ASSERT(FALSE);
		return;
	}
	m_MapDc=NULL;
	m_hOldDc = ::SelectObject (m_NewDc, *bmMap);
}

CMemDc::~CMemDc(void)
{
	DeleteObject(m_NewDc);
	if (m_MapDc)
		DeleteObject(m_MapDc);
}

HDC CMemDc::GetGetSafeHDC()
{
	return m_NewDc;
}